/* http://www.codeplex.com/animej */
var __DependenciesManager;function BlueScreen(msg) {if (document.body) {alert('onloaded');var d = document.createElement('div'), k;var values = { 'position': 'absolute', 'top': 0, 'left': 0, 'width': '100%',
'height': '100%', 'background': 'Blue', 'color': 'White', 'fontFamily': 'Fixedsys, monospace' };for (k in values) d.style[k] = values[k];d.innerHTML = 'INTERNAL ERROR: '+msg;d.onclick = function () { document.body.removeChild(d); };document.body.appendChild(d);} else {document.write('<div style="z-index: 1000; position: absolute; left: 0; top: 0; margin: 0; padding: 0; width: 100%; height: 100%; background: Blue; color: White; font-family: Fixedsys, monospace" onclick="this.parentNode.removeChild(this);">INTERNAL ERROR: '+msg+'</div>');}
throw "INTERNAL ERROR: " + msg;}
function RegisterScript(name, version, description) {if (! __DependenciesManager) __DependenciesManager = {};__DependenciesManager[name + ", version=" + version] = description;}
function Require(scripts) {var i, msg = null;for (i = 0; i < scripts.length; i++) {var el = scripts[i], k, strong = typeof(el) != "string";if (strong && !el.Name) {msg = "Invalid require statement!";BlueScreen(msg);return;}
var toadd = strong ? el.Name + ' (version ' + el.Version + ')' : el;for (k in __DependenciesManager)if (!strong) {if (k.indexOf(el) == 0) {toadd = null;break;}} else {if (k.indexOf(el.Name) == 0) {var v = parseInt(k.substring(k.indexOf(", version=") + 10));if (el.Version && el.Version <= v) {toadd = null;break;}}}
if (toadd)if (msg) msg += ", " + toadd;else msg = toadd;}
if (msg) BlueScreen('Missing libraries are <br><br>' + msg);}
RegisterScript('AnimeJ', 1, 'AnimeJ animation library');function AnimeJHeap() {var obj = this;var pos = 0;var left = function(idx) {return (2 * (idx + 1) - 1);}
var right = function (idx) {return (2 * (idx + 1));}
var parent = function (idx) {return (Math.floor((idx + 1) / 2) - 1);}
var swap = function (a, b) {var tmp = obj[a];obj[a] = obj[b];obj[b] = tmp;}
var percolateUp = function (p) {var par = parent(p);while ((p > 0) && (obj[p].Due < obj[par].Due)) {swap(p, par);p = par;par = parent(p);}}
var percolateDown = function (p) {var l = left(p), r = right(p);if (l < pos) {if (r < pos) {if (obj[l].Due > obj[r].Due) {swap(p, r);percolateDown(r);} else {swap(p, l);percolateDown(l);}} else {swap(p, l);percolateDown(l);}} else if (p != pos - 1) {swap(p, pos - 1);percolateUp(p);}}
this.Count = function () { return pos; }
this.Insert = function (el) {this[pos] = el;percolateUp(pos++);}
this.Top = function () {if (pos)return this[0];return null;}
this.Remove = function () {var ret = null;if (!pos) return ret;ret = this[0];percolateDown(0);this[pos--] = null;return ret;}
this.RemoveTask = function (t) {var i, ret = -1;for (i = 0; i < pos; i++)if (this[i].Task == t) {ret = this[i].Due;percolateDown(i);this[pos--] = null;break;}
return ret;}
this.ToString = function () {var i, ret = "";for (i = 0; i < pos; i++)ret += " <i>" + i + ":</i> " + this[i].Due;return ret;}}
var AnimeJTaskPrototype = {DoAction: function (delay) {}}
var AnimeJInterpolatedTaskPrototype = {OnPause: function () {},
OnResume: function () {},
OnStop: function () {}}
AnimeJInterpolatedTaskPrototype.prototype = AnimeJTaskPrototype;var AnimeJTimerRunning = null;function AnimeJTimer() {this.Start = new Date();this.Heap = new AnimeJHeap();this.Time = function () {return new Date() - this.Start;}
this.SetAlertMillis = function(what, when) {var exp = when + this.Time();this.Heap.Insert({ 'Due': exp, 'Task': what });if (AnimeJTimerRunning != null && this.Heap.Top().Due == exp) {clearTimeout(AnimeJTimerRunning);AnimeJTimerRunning = null;}
if (AnimeJTimerRunning == null) {AnimeJTimerRunning = true;var tosleep = this.Heap.Top().Due - this.Time();tosleep = 0 > tosleep ? 1 : tosleep;AnimeJTimerRunning = setTimeout('AnimeJTimerTick()', tosleep);}}
this.RemoveTask = function (t) {var v = this.Heap.RemoveTask(t);if (v > -1) {v = v - this.Time();if (v < 0) v = 0;}
return v;}
this.SetAlertDate = function (what, when) {var t = when - this.Start;this.SetAlertMillis(what, t);}}
var AnimeJGlobalTimer = new AnimeJTimer();function AnimeJTimerTick() {var t = AnimeJGlobalTimer;var currt = t.Time() + 10;while (t.Heap.Count() > 0 && currt >= t.Heap.Top().Due) {var el = t.Heap.Remove();el.Task.DoAction(currt - el.Due);}
if (t.Heap.Count() > 0) {currt = t.Time();AnimeJTimerRunning = setTimeout('AnimeJTimerTick()', t.Heap.Top().Due - currt);} else {AnimeJTimerRunning = null;}}
function AnimeJConv() {}
AnimeJConv.Int = function (from, to, v) {return Math.floor(from + (to - from)*v);};AnimeJConv.Float = function (from, to, v) {return from + (to - from)*v;};AnimeJConv.Discrete = function (from, to, v) {return v < 0.5 ? from : to;};AnimeJConv.IntList = function (from, to, v) {var ret = new Array(), i;for (i = 0; i < from.length; i++)ret.push(Math.floor(from[i] + (to[i] - from[i])*v));return ret;};AnimeJConv.FloatList = function (from, to, v) {var ret = new Array(), i;for (i = 0; i < from.length; i++)ret.push(from[i] + (to[i] - from[i])*v);return ret;};function AnimeJLinearInterpolator(obj, prop, steps, conv, prefix, suffix) {var i, last = 0.0;if (steps.length < 2) throw "Invalid steps: length less than 2";if (steps[0].t != 0.0) throw "Invalid steps: timeline must start at 0.0!";if (steps[steps.length - 1].t != 1.0) throw "Invalid steps: timeline must end with 1.0!";for (i = 1; i < steps.length; i++) {if (steps[i].t > 1.0 || steps[i].t < 0.0 || steps[i].t <= last)throw "Invalid steps: invalid value "+(steps[i].t) +"!";last = steps[i].t;}
this.Compute = function (v) {var idx;for (idx = 1; idx < steps.length; idx++)if (steps[idx].t >= v) break;idx--;var val = conv(steps[idx].v, steps[idx + 1].v, (v - steps[idx].t)/(steps[idx + 1].t - steps[idx].t));if (typeof(obj) == 'function')obj(val);else obj[prop] = prefix + val + suffix;}}
function AnimeJInterpolatedTask(interp, ms, stepms) {this.prototype = AnimeJInterpolatedTaskPrototype;this.Duration = ms;this.Start = - 1;this.Reverse = false;this.OnPause = function() {if (this.Start != -1)this.Start = AnimeJGlobalTimer.Time() - this.Start;}
this.OnResume = function() {if (this.Start != -1)this.Start = AnimeJGlobalTimer.Time() - this.Start;}
this.OnStop = function() {this.Start = -1;}
this.DoAction = function (d) {if (this.Start == -1)this.Start = AnimeJGlobalTimer.Time();var t = AnimeJGlobalTimer.Time();var v = (t - this.Start) / this.Duration;v = v > 1 ? 1 : v;interp.Compute(this.Reverse ? 1 - v : v);var t1 = AnimeJGlobalTimer.Time();var next = stepms - d + t1 - t;if (v < 1)AnimeJGlobalTimer.SetAlertMillis(this, next);else this.Start = -1;}}
function AnimeJTimelineCallBackTask(t, prop) {this.prototype = AnimeJTaskPrototype;this.DoAction = function (d) {if (t[prop])(t[prop])(d);}}
function AnimeJFunctionCallbackTask(fun) {this.prototype = AnimeJTaskPrototype;this.DoAction = function (d) {fun(d);}}
function Timeline() {var Paused = 0;var OnEndCB = null;var Data = {};var Running = false;var Reverse = false;this.IsPaused = function () {return Paused != 0;}
this.IsRunning = function () {return Running;}
this.InternalOnEnd = function (d) {Runnning = false;if (this['OnEnd']) this['OnEnd'](d, Reverse);}
this.Run = function (reverse) {Reverse = reverse ? true : false;Running = true;var max = 0;for (v in Data) {var el = Data[v];var startAt = parseInt(v);var i = 0;if (startAt > max) max = startAt;for (i = 0; i < el.length; i++) {el[i].Reverse = Reverse;if (el[i].Duration && (startAt + el[i].Duration) > max) max = startAt + el[i].Duration;AnimeJGlobalTimer.SetAlertMillis(el[i], startAt);}}
var tm = this;OnEndCB = new AnimeJTimelineCallBackTask(tm, 'InternalOnEnd');AnimeJGlobalTimer.SetAlertMillis(OnEndCB, max);}
this.SetAt = function (timems, task) {if (Data[timems])Data[timems].push(task);else Data[timems] = new Array(task);}
this.Stop = function () {Running = false;Paused = 0;var t = AnimeJGlobalTimer;var tm, i, v;if (OnEndCB != null) {tm = t.RemoveTask(OnEndCB);OnEndCB = null;}
for (v in Data) {var el = Data[v];for (i = 0; i < el.length; i++) {tm = t.RemoveTask(el[i]);el[i].OnStop();}}}
this.Pause = function () {if (Paused) return;Paused = 1;var t = AnimeJGlobalTimer;var tm, i, v;if (OnEndCB != null) {tm = t.RemoveTask(OnEndCB);if (tm > -1)OnEndCB.Paused = tm;else OnEndCB = null;}
for (v in Data) {var el = Data[v];for (i = 0; i < el.length; i++) {tm = t.RemoveTask(el[i]);if (tm == 0) tm = 1;el[i].OnPause();if (tm > -1)el[i].Paused = tm;}}}
this.Resume = function () {if (!Paused) throw "Timeline not paused!";Paused = 0;var t = AnimeJGlobalTimer;var tm, i, v;if (OnEndCB != null) {t.SetAlertMillis(OnEndCB, OnEndCB.Paused);OnEndCB.Paused = 0;}
for (v in Data) {var el = Data[v];for (i = 0; i < el.length; i++) {if (el[i].Paused) {t.SetAlertMillis(el[i], el[i].Paused);el[i].Paused = 0;}
el[i].OnResume();}}}}
var AnimeIsIE = navigator.appVersion.indexOf("MSIE") != -1;var AnimeIEVer = AnimeIsIE ? parseFloat(navigator.appVersion.match(/MSIE\s([0-9\.]+)/)[1]) : -1;function AnimeSetOpacity(obj, value) {if (AnimeIsIE) {obj.style.filter = "alpha(opacity=" + (Math.floor(value * 100)) + ")";} else {obj.style.opacity = value;}}
function AnimeJInterp() {}
AnimeJInterp.px = function (time, tstep, obj, prop, fromOrSteps, to) {if (typeof(fromOrSteps) == 'number')fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(obj, prop, fromOrSteps, AnimeJConv.Int, '', 'px'), time, tstep);};AnimeJInterp.alpha = function (time, tstep, obj, fromOrSteps, to) {if (typeof(fromOrSteps) == 'number')fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];var change = function (v) {AnimeSetOpacity(obj, v);}
return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(change, null, fromOrSteps, AnimeJConv.Float, '', ''), time, tstep);};AnimeJInterp.fiv = function (time, tstep, fun, fromOrSteps, to) {if (to)fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(fun, null, fromOrSteps, AnimeJConv.Int, '', ''), time, tstep);};AnimeJInterp.ffv = function (time, tstep, fun, fromOrSteps, to) {if (to)fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(fun, null, fromOrSteps, AnimeJConv.Float, '', ''), time, tstep);};AnimeJInterp.fia = function (time, tstep, fun, fromOrSteps, to) {if (to)fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(fun, null, fromOrSteps, AnimeJConv.IntList, '', ''), time, tstep);};AnimeJInterp.ffa = function (time, tstep, fun, fromOrSteps, to) {if (to)fromOrSteps = [ { t: 0.0, v: fromOrSteps}, { t: 1.0, v: to } ];return new AnimeJInterpolatedTask(new AnimeJLinearInterpolator(fun, null, fromOrSteps, AnimeJConv.FloatList, '', ''), time, tstep);};